package com.six.work.controller;

import com.six.work.entity.*;
import com.six.work.services.InvitationServices;
import com.six.work.services.PositionServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("position")
public class PositionController {
    @Autowired
    private PositionServices positionServices;

    @GetMapping("/list")
    public List<PositionView> findAllPosition(@RequestParam(value = "positionName", defaultValue = "") String positionName,
                                            @RequestParam(value = "state_id", defaultValue = "0") Integer state_id) {
        List<PositionView> lists = null;
        if (state_id==0) {  //没有选择状态的时候
            lists = positionServices.findPositionByName(positionName);
        } else {
            lists = positionServices.finPositionByStateAndcomName(positionName, state_id);
        }
        return  lists;
    }

    @GetMapping("/list2")
    public List<Position> findPositionAndCompany() {
        List<Position> list = positionServices.findPositionAndCompany();
        return  list;
    }

    @GetMapping("/list4")
    public List<Position> findPositionAndCompany1(){
        List<Position> list = positionServices.findPositionAndCompany1();
        return list;
    }

    @GetMapping("/list5")
    public List<CompanyAndPositionView> findPositionAndCompany2(){
        List<CompanyAndPositionView> list = positionServices.findPositionAndCompany2();
        return list;
    }


    @GetMapping("/update")
    public String updatePositionState(@RequestParam("position_id") Integer position_id) {
        return positionServices.updatePositionState(position_id);
    }

    @GetMapping("/update1")
    public String updatePositionState1(@RequestParam("position_id") Integer position_id) {
        return positionServices.updatePositionState1(position_id);
    }

    @GetMapping("/look")
    public Position getLookPage(@RequestParam("position_id") Integer position_id) {
        return positionServices.SelectPositionByID(position_id);
    }

    //前端连数据库
    @GetMapping("/list1")
    public List<Position> findAllPosition1() {
        List<Position> list = positionServices.findAllPosition1();
        return list;
    }

    //按工作地点查询
   @GetMapping("/addlist")
   public List<Position> findPositionByAdd(String job_add) {
        List<Position> list = positionServices.findPositionByAdd(job_add);
       return list;
   }
   ////按细分方向查询
    @GetMapping("/typelist")
    public List<Position> findPositionByType(String job_type) {
        List<Position> list = positionServices.findPositionByType(job_type);
        return list;
    }

    //按薪资查询
    @GetMapping("/paylist")
    public List<Position> findPositionByPay(String job_pay) {
        List<Position> list = positionServices.findPositionByPay(job_pay);
        return list;
    }

    //发布职位
    @GetMapping("/list3")
    public List<Position> findAllPositions(){
        List<Position> list = positionServices.findAllPositions();
        return list;
    }

    @PostMapping("/add")
    public Integer InsertPosition(@RequestBody Position position){

        return positionServices.insertPosition(position);
    }

    @GetMapping("/typelist1")
    public List<Position> findComJobType(){
        List<Position> list=positionServices.findComJobType();
        return list;
    }

    @GetMapping("/success")
    public List<CompanyState> findSuccessCom() {
        List<CompanyState> list=positionServices.findSuccessCom();
        return list;
    }

//    @PostMapping("/login")
//    public Integer UserLogin(@RequestBody Student student) {
//        Student stu = studentServices.UserLogin(student.getStu_name());
//
//        if (stu != null) { //stu返回对象不为空则表示，用户名正确
//            if (stu.getPassword().equals(student.getPassword())) { //为真则表示，密码正确
//                return 200;
//            } else {  //为假则表示，密码错误
//                return 201;
//            }
//        } else { //stu返回对象为空则表示，用户不正确
//            return 202;
//        }
//    }


    //前端页面间Aworkposition传值到positionItem(试)
    @GetMapping("/post1")
    public List<CompanyAndPositionView> SelectPositionByID2(@RequestParam("position_id") Integer position_id) {
        return positionServices.SelectPositionByID2(position_id);
    }

    //11——13
    @GetMapping("/post2")
    public List<Position> SelectPositionByID3(@RequestParam("company_id") Integer company_id) {
        return positionServices.SelectPositionByID3(company_id);
    }

    //今日新增
    @GetMapping("/today")
    public Integer findTodayCom(){
        return positionServices.FindTodayCom();
    }

    //本月新增
    @GetMapping("/month")
    public Integer findMonthCom(){
        return positionServices.FindMonthCom();
    }

    //职位 饼图
    @GetMapping("/pie2")
    public List<Position> sumJobType() {
        List<Position> list = positionServices.sumJobType();
        return list;
    }

    //热门投递职位top 10
    @GetMapping("/top10")
    public List<Position> jobTop10(){
        List<Position> list =  positionServices.jobTop10();
        return list;
    }


    //查看公司发布的职位
    @GetMapping("/ClistP")
    public List<Position> ComPosition(Integer company_id) {
        List<Position> list = positionServices.ComPosition(company_id);
        return list;
    }

    @GetMapping("/del")
    public Integer deleteByID(@RequestParam("position_id") Integer position_id){
        return positionServices.DelPositionByID(position_id);
    }
}

